package com.suse.springbook.model;

import com.suse.springbook.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String errMsg;
    private T data;

    public static <T> Result<T> nologin() {
        //用户未登录
        Result result = new Result<>();
        result.setCode(ResultCodeEnum.NOLOGIN.getCode());
        result.setErrMsg("用户未登录");
        return result;
    }

    public static <T> Result<T> success(T data) {

        Result result = new Result<>();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        //失败时
        Result result = new Result<>();
        result.setErrMsg(errMsg);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setData(null);
        return result;
    }

}
